<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<style>
    .control-label {
        margin: 10px;
        width: 80px;
    }
</style>
<script type="text/javascript">
    $(function () {
        initSelect(false, "#typeList", ${typeList}, true);

        $.CurrentDialog.find("#fileUpload").upload({
            uploader: "filesupload/uploadify/document/Article.shtml",
            fileSizeLimit: 1024,
            buttonText: "点击上传新总结",
            fileTypeExts: "*.doc;*.docx",
            icon: "cloud-upload",
            onUploadSuccess: "fileUploadSuccess",
            multi: "true",
            previewImg: false
        });
    });

    /***
     * 文件上传回调
     */
    function fileUploadSuccess(file, data, $element) {
        var json = $.parseJSON(data);
        if (json.code != 0) {
            $(this).alertmsg('error',json.msg);
            return;
        }
        var file = json.data;
        var filename = file.name;
        var fileNo = file.no;
        var addli = '<li style="margin: 4px;" id="' + fileNo + '"><a class="btn btn-gray">' + filename + '</a>&nbsp;&nbsp;&nbsp;&nbsp;' +
            '<a	class="btn btn-red"  data-mask="true" data-toggle="doajax" data-confirm-msg="请确认是否删除当前文件？" data-callback="delfileBack"  href="filesupload/deleteWordForDoc/' + fileNo + '.shtml">删除</a>' +
            '</li>';
        console.log(filename)
        $.CurrentDialog.find("#fileNo").val(fileNo);
        $.CurrentDialog.find("#filename").append(addli);
        $.CurrentDialog.find("#uploadtr").hide();
    }

    /**
     * 文件删除
     */
    function delfileBack(json) {
        if (json.code == 0) {
            $(this).alertmsg('ok', '' + json.msg);
            $.CurrentDialog.find("#" + json.data).remove();
            $.CurrentDialog.find("#fileNo").val("");
            $.CurrentDialog.find("#uploadtr").show();
        } else {
            $(this).alertmsg('error', '' + json.msg);
        }
    }

    function check() {
        var fileno = $.CurrentDialog.find("#fileNo").val();
        if(Dracula.util.isEmpty(fileno)){
            $(this).alertmsg('error', "必须上传文章文件");
            return false
        }
        return true
    }
</script>
<div class="bjui-pageContent">
    <form action="document/article/add.shtml" class="pageForm" id="addForm"
          data-toggle="validate" data-callback="doAjaxCallBackForDialog"
          method="post" data-toggle="ajaxform"
          data-validator-option="{stopOnError:false, timely:2}">
        <div class="panel panel-default">
            <div class="panel-body">
                <table class="table table-condensed table-hover">
                    <tbody>
                    <tr>
                        <td width="100px"><label class="control-label x100">标题：</label></td>
                        <td>
                            <input type="text"  id="name" name="name" class="form-control"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="100px"><label class="control-label x100">类型：</label></td>
                        <td>
                            <select id="typeList" name="type" data-width="200"
                                    class="form-control" data-toggle="selectpicker" data-size="200">
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <td width="100px"><label class="control-label x100">评论：</label></td>
                        <td>
                            <textarea cols="40" name="comment"></textarea>
                        </td>
                    </tr>
                    <tr id="uploadtr">
                        <td width="100px"><label class="control-label x100">上传文章：</label></td>
                        <td>
                            <div>
                                <input type="hidden" id="fileNo" name="fileNo"/>
                                <div id="fileUpload" data-toggle="upload" style="display: inline;"></div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <ul id="filename" style="font-size: 16px;display:inline;">
                            </ul>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </form>
</div>
<div class="bjui-pageFooter">
    <ul>
        <li>
            <button type="submit" class="btn-primary" onClick="return check()">保存
            </button>
        </li>
        <li>
            <button type="button" class="btn-close">关闭</button>
        </li>
    </ul>
</div>